﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tilver.Coder.Core;
using Tilver.Coder.Utility;

namespace Tilver.Coder.Engine
{
    public class ViewEngine : EngineBase, IViewEngine
    {
        public CoderView View { get; set; }

        public override string RenderToString()
        {
            var response = new StringBuilder();
            ResponseClass(response, Tabs);
            return response.ToString();
        }

        private void ResponseClass(StringBuilder response, int tabs)
        {
            //输出引入命令空间
            base.ResponseNameSpaces(response, tabs);
            response.AppendLine();
            response.AppendFormatLine(tabs, "namespace {0}", NameSpace);
            response.AppendTabLine(tabs, "{");

            response.AppendTabLine(tabs + 1, "#region EO");
            response.AppendLine();
            #region 输出实体类
            var viewEOEngine = new ViewEOEngine();
            viewEOEngine.DBTextStyle = DBTextStyle;
            viewEOEngine.NameSpace = NameSpace;
            viewEOEngine.Tabs = tabs + 1;
            viewEOEngine.View = View;
            response.AppendLine(viewEOEngine.RenderToString());
            #endregion
            response.AppendLine();
            response.AppendTabLine(tabs + 1, "#endregion");

            response.AppendTabLine(tabs + 1, "#region MO");
            response.AppendLine();
            #region 输出操作类
            var viewMOEngine = new ViewMOEngine();
            viewMOEngine.DBTextStyle = DBTextStyle;
            viewMOEngine.NameSpace = NameSpace;
            viewMOEngine.Tabs = tabs + 1;
            viewMOEngine.View = View;
            response.AppendLine(viewMOEngine.RenderToString());
            #endregion
            response.AppendLine();
            response.AppendTabLine(tabs + 1, "#endregion");

            response.AppendTabLine(tabs, "}");
        }
    }
}
